package jam.UserInterface.UI;
import java.awt.ComponentOrientation;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.*;
import javax.swing.*;
import java.io.File;
import javax.imageio.ImageIO;


public class userOptions extends JFrame implements ActionListener,KeyListener,MouseListener {
	
	private JFrame userOpWindow = new JFrame();
	private JLabel fName = new JLabel();
	private JLabel lName = new JLabel();
	private JLabel nName = new JLabel();
	private JLabel uStatus = new JLabel();
	
	private JTextField firstName = new JTextField();
	private JTextField lastName = new JTextField();
	private JTextField nickName = new JTextField();
	
	private JButton update = new JButton();
	private JButton cancel = new JButton();
	
	private String[] status = {"Online", "Away", "Busy", "Offline"};
	private JComboBox userStatus = new JComboBox(status);
	
	public userOptions(){
		//optional look and feel
		UIManager.LookAndFeelInfo[] lfi= UIManager.getInstalledLookAndFeels();
		    
		try
		{
		UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		}
		catch (Exception e)
		{
		System.out.println("Can't set chosen look-and-feel!");
	    }

		userOpWindow.setDefaultLookAndFeelDecorated(true);
		

		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		userOpWindow.setBounds(((int)(screenSize.getWidth()-400))/2,((int)(screenSize.getHeight()-400))/2,400,400);
		userOpWindow.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		userOpWindow.setLayout(new GridBagLayout());
		userOpWindow.setTitle("User Options");
		
		//change the icon code
		String currentDirectory = System.getProperty("user.dir");
		try {
			Image image = ImageIO.read(new File(currentDirectory + "/src/jam/UserInterface/Icons/JAMicon.png"));
			userOpWindow.setIconImage(image);
		}catch (Exception e){System.out.println("The file could not be read!!!!");}
		
		GridBagConstraints c = new GridBagConstraints();
		
		userOpWindow.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
		
		c.weightx = 0.5;
		c.fill = GridBagConstraints.HORIZONTAL;
		c.gridx = 0;
		c.gridy = 0;
		fName.setText("First Name:");
		userOpWindow.add(fName,c);
		
		JLabel spacing = new JLabel();
		spacing.setText("");
		
		c.weightx = 0.5;
		c.fill = GridBagConstraints.HORIZONTAL;
		c.gridx = 1;
		c.gridy = 0;
		userOpWindow.add(spacing,c);
		
		c.weightx = 0.5;
		c.fill = GridBagConstraints.HORIZONTAL;
		c.gridx = 2;
		c.gridy = 0;
		firstName.addKeyListener(this);
		userOpWindow.add(firstName,c);
		
		c.weightx = 0.5;
		c.fill = GridBagConstraints.HORIZONTAL;
		c.gridx = 0;
		c.gridy = 1;
		lName.setText("Last Name:");
		userOpWindow.add(lName,c);
		
		JLabel spacing1 = new JLabel();
		spacing1.setText("");
		
		c.weightx = 0.5;
		c.fill = GridBagConstraints.HORIZONTAL;
		c.gridx = 1;
		c.gridy = 1;
		userOpWindow.add(spacing1,c);
		
		c.weightx = 0.5;
		c.fill = GridBagConstraints.HORIZONTAL;
		c.gridx = 2;
		c.gridy = 1;
		lastName.addKeyListener(this);
		userOpWindow.add(lastName,c);
		
		c.weightx = 0.5;
		c.fill = GridBagConstraints.HORIZONTAL;
		c.gridx = 0;
		c.gridy = 2;
		nName.setText("Nick Name:");
		userOpWindow.add(nName,c);
		
		JLabel spacing2 = new JLabel();
		spacing2.setText("");
		
		c.weightx = 0.5;
		c.fill = GridBagConstraints.HORIZONTAL;
		c.gridx = 1;
		c.gridy = 2;
		userOpWindow.add(spacing2,c);
		
		c.weightx = 0.5;
		c.fill = GridBagConstraints.HORIZONTAL;
		c.gridx = 2;
		c.gridy = 2;
		nickName.addKeyListener(this);
		userOpWindow.add(nickName,c);
		
		c.weightx = 0.5;
		c.fill = GridBagConstraints.HORIZONTAL;
		c.gridx = 0;
		c.gridy = 3;
		uStatus.setText("Status:");
		userOpWindow.add(uStatus,c);
		
		JLabel spacing3 = new JLabel();
		spacing3.setText("");
		
		c.weightx = 0.5;
		c.fill = GridBagConstraints.HORIZONTAL;
		c.gridx = 1;
		c.gridy = 3;
		userOpWindow.add(spacing3,c);
		
		c.weightx = 0.5;
		c.fill = GridBagConstraints.HORIZONTAL;
		c.gridx = 2;
		c.gridy = 3;
		userStatus.setSelectedIndex(0);
		userOpWindow.add(userStatus,c);
		
		c.weightx = 0.5;
		c.fill = GridBagConstraints.HORIZONTAL;
		c.gridx = 0;
		c.gridy = 4;
		update.setText("Update");
		update.addActionListener(this);
		userOpWindow.add(update,c);
		
		JLabel spacing4 = new JLabel();
		spacing4.setText("");
		
		c.weightx = 0.5;
		c.fill = GridBagConstraints.HORIZONTAL;
		c.gridx = 1;
		c.gridy = 4;
		userOpWindow.add(spacing4,c);
		
		c.weightx = 0.5;
		c.fill = GridBagConstraints.HORIZONTAL;
		c.gridx = 2;
		c.gridy = 4;
		cancel.setText("Cancel");
		cancel.addActionListener(this);
		userOpWindow.add(cancel,c);
		
		userOpWindow.setVisible(true);
		
	}

	@Override
	public void mouseClicked(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseEntered(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseReleased(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void keyPressed(KeyEvent e) {
		// TODO Auto-generated method stub
		if (e.getSource() == firstName && e.getKeyCode() == KeyEvent.VK_TAB){
			lastName.setCaretPosition(0);
		}
		else if(e.getSource() == lastName && e.getKeyCode() == KeyEvent.VK_TAB){
			nickName.setCaretPosition(0);
		}
		else if (e.getSource() == nickName && e.getKeyCode() == KeyEvent.VK_TAB){
			userStatus.setFocusable(true);
		}
		
	}

	@Override
	public void keyReleased(KeyEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void keyTyped(KeyEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		if (e.getSource() == update){
			System.out.println("I NOW NEED TO GO ABOUT THE PAIN IN THE ASS THING OF PASSING STUFF BETWEEN WINDOWS");
			userOpWindow.dispose();
		}
		else if (e.getSource() == cancel){
			userOpWindow.dispose();
		}
		
		
	}

}
